package com.pets.controller;

import com.pets.entity.Animal;
import com.pets.entity.Users;
import com.pets.qo.AppointmentAddQO;
import com.pets.qo.KnowledgeAddQO;
import com.pets.service.AnimalService;
import com.pets.service.AppointmentService;
import com.pets.service.KnowledgeService;
import com.pets.service.UserService;
import com.pets.util.PageData;
import com.pets.util.Result;
import com.pets.vo.AnimalVO;
import com.pets.vo.KnowledgesByPageVO;
import com.pets.vo.UserAdoptRecodeVO;
import com.pets.vo.UserCoverAdoptRecodeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value="/appointment")
public class AppointmentController {
    @Autowired
     private AppointmentService appointmentService;
    @Autowired
    private AnimalService animalService;

    @RequestMapping(value = "/appointmentAdd01")
    public ModelAndView appointmentAdd01(int aId){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/user/appointment");
        AnimalVO a=animalService.show(aId);
        modelAndView.addObject("a",a);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(value = "/appointmentAdd02", method = RequestMethod.POST)
    public Result appointmentAdd02(AppointmentAddQO appointmentAddQO) {
    Result result=appointmentService.AppointmentAdd(appointmentAddQO);

        return result;
    }

    /**
     * 到用户领养记录列表
     * @return
     */
    @RequestMapping(value = "/toUserAdoptRecode" )
    public ModelAndView toUserAdoptRecode(int uId){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user/adopt_record");
        List<UserAdoptRecodeVO> vos = appointmentService.getUserAdoptRecode(uId);
        modelAndView.addObject("voList",vos);
        return modelAndView;
    }

    /**
     * 用户取消领养申请
     * @param apId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/cancelApply" ,method = RequestMethod.POST)
    public Result cancelApply(int apId){
        return appointmentService.cancelApply(apId);
    }

    /**
     * 到机构被领养记录列表
     * @return
     */
    @RequestMapping(value = "/toUserCoverAdoptRecode" )
    public ModelAndView toUserCoverAdoptRecode(int uId){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user/adopt_cover_record");
        //查询自己宠物的领养记录
        List<UserCoverAdoptRecodeVO> vos = appointmentService.getUserCoverAdoptRecode(uId);
        //查询自己发布的宠物记录
        List<Animal> animals = animalService.getUserAnimal(uId);
        modelAndView.addObject("coverVoList",vos);
        modelAndView.addObject("animalList",animals);
        return modelAndView;
    }

    /**
     * 机构同意领养
     * @param apId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/agreeApply" ,method = RequestMethod.POST)
    public Result agreeApply(int apId){
        return appointmentService.agreeApply(apId);
    }

    /**
     * 机构不同意领养
     * @param apId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/disagreeApply" ,method = RequestMethod.POST)
    public Result disagreeApply(int apId){
        return appointmentService.disagreeApply(apId);
    }


    /**
     * 机构下架流浪动物
     * @param aId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/shelvesAnimal" ,method = RequestMethod.POST)
    public Result shelvesAnimal(int aId){
        return appointmentService.shelvesAnimal(aId);
    }
}
